import request from '@/utils/request'

// 获取向量知识库列表
export function getVectorKnowledgeBaseList(args) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${args && ('?' + args) || ''}`,
    method: 'get'
  })
}

// 创建向量知识库
export function createVectorKnowledgeBase(data) {
  return request({
    url: '/chatbot/api/vector-knowledge-base/',
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

// 获取向量知识库详情
export function getVectorKnowledgeBaseDetail(id) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/`,
    method: 'get'
  })
}

// 更新向量知识库
export function updateVectorKnowledgeBase(id, data) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/`,
    headers: { 'content-type': 'application/json' },
    method: 'put',
    data: data
  })
}

// 删除向量知识库
export function deleteVectorKnowledgeBase(id) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/`,
    method: 'delete'
  })
}

// 添加文档链接
export function addDocumentLink(id, data) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/add-document-link/`,
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

// 移除文档链接
export function removeDocumentLink(id, data) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/remove-document-link/`,
    headers: { 'content-type': 'application/json' },
    method: 'delete',
    data: data
  })
}

// 获取 Qdrant 配置
export function getQdrantConfig(id) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/qdrant-config/`,
    method: 'get'
  })
}

// 上传文档
export function uploadDocument(id, data) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/upload-document/`,
    headers: { 'content-type': 'multipart/form-data' },
    method: 'post',
    data: data
  })
}

// 上传URL
export function uploadUrl(id, data) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/upload-url/`,
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

// 搜索知识库
export function searchKnowledgeBase(id, data) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/search/`,
    headers: { 'content-type': 'application/json' },
    method: 'post',
    data: data
  })
}

// 获取搜索结果
export function getSearchResult(id, args) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/search-result/${args && ('?' + args) || ''}`,
    method: 'get'
  })
}

// 获取搜索结果（支持任务ID查询）
export function getSearchResultByTaskId(id, taskId) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/search-result/?task_id=${taskId}`,
    method: 'get'
  })
}

// 获取文档列表
export function getDocuments(id, args) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/documents/${args && ('?' + args) || ''}`,
    method: 'get'
  })
}

// 删除文档
export function deleteDocument(id, docId) {
  return request({
    url: `/chatbot/api/vector-knowledge-base/${id}/documents/${docId}/`,
    method: 'delete'
  })
}
